package com.ycode.bang.anbang.activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.ycode.bang.anbang.MyApp;
import com.ycode.bang.anbang.R;
import com.ycode.bang.anbang.baseui.BaseActivity;
import com.ycode.bang.anbang.model.RepairFeeScale;
import com.ycode.bang.anbang.network.FinalHttpUtil;
import com.ycode.bang.anbang.utils.RequestMapDev;
import com.ycode.bang.anbang.utils.SetImage;
import com.ycode.bang.anbang.utils.ToastUtil;

import net.tsz.afinal.http.AjaxCallBack;
import net.tsz.afinal.http.AjaxParams;

import org.json.JSONObject;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by maosongsong
 * Description : 显示网页的界面
 */
public class WebViewActivity extends BaseActivity {
    @InjectView(R.id.title)
    TextView title1;
    @InjectView(R.id.text)
    TextView text;
    @InjectView(R.id.image)
    ImageView image;
    Intent intent;
    private String plotid = "";

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_web);
        ButterKnife.inject(this);
        intent = this.getIntent();
        plotid = intent.getStringExtra("plotid");
        title1.setText("收费标准");
        initView();
    }

    @Override
    protected void getSuccessRequest(Object response, int flag) {

    }

    private void initView() {
        getInformation();
    }

    private void getInformation() {
        AjaxParams mAjaxParam = new AjaxParams();
        mAjaxParam.put("csrfToken", MyApp.instance.getToken());
        mAjaxParam.put("villageId", plotid);
        FinalHttpUtil.get(RequestMapDev.repairFeeScale, mAjaxParam, new AjaxCallBack<String>() {
            @Override
            public void onSuccess(String o) {
                super.onSuccess(o);
                //放置数据
                try {
                    JSONObject jsonObject = new JSONObject(o.toString());
                    String status = jsonObject.getString("status");
                    String msg = jsonObject.getString("message");
                    String data = jsonObject.getString("data");
                    if (status.equals("0")) {
                        Log.e("这个接口是成功的", o);
                        Gson gson = new Gson();
                        RepairFeeScale repairFeeScale = new RepairFeeScale();
                        repairFeeScale = gson.fromJson(data, RepairFeeScale.class);
                        text.setText(repairFeeScale.getFeeScale());
                        SetImage.setimage(WebViewActivity.this, repairFeeScale.getPicture(), image);
                    } else {
                        ToastUtil.show(WebViewActivity.this, msg.toString());
                    }
                } catch (Exception e) {
//                    ToastUtil.show(RepairingDetailActivity.this, e.toString());
                }
            }

            @Override
            public void onFailure(Throwable t, int errorNo, String strMsg) {
                loginout_550(errorNo);
//                ToastUtil.show(.this, strMsg);
            }
        });
    }
}
